package com.tao.com.xiaowen.config.tecent;

import android.content.Context;

import com.tao.com.xiaowen.config.http.MyJson;
import com.tao.com.xiaowen.model.BmobUserAuth;
import com.tao.com.xiaowen.model.Model;
import com.tencent.tauth.Tencent;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobUser;

/**
 * Created by Administrator on 2016/8/8.
 */
public class GetUserAuth {
    public static String getUserAyth(Tencent tencent, Context context) {
        Bmob.initialize(context, Model.APP_ID_BMOB);
        BmobUser bmobUser = BmobUser.getCurrentUser();
        String expires_in = null;
        if (bmobUser != null) {
            Object jsonData = BmobUser.getObjectByKey("authData");
            if (jsonData != null) {
                BmobUserAuth userAuth = MyJson.getBmobUserAuth(jsonData);
                String openid = userAuth.getOpenid();

                String access_token = userAuth.getAccess_token();
                expires_in = userAuth.getExpires_in(); // 实际值需要通过上面介绍的方法来计算
                tencent = Tencent.createInstance(Model.APP_ID_QQ, context);
                tencent.setOpenId(openid);
                tencent.setAccessToken(access_token, expires_in);
            }
        } else

        {

        }

        return expires_in;
    }
    public static BmobUser getUserAth(Context context) {
        Bmob.initialize(context, Model.APP_ID_BMOB);
        BmobUser bmobUser = BmobUser.getCurrentUser();

        return bmobUser;
    }
}
